package com.clip.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.springframework.stereotype.Repository;

import com.clip.entity.NoticeItem;
import com.clip.entity.Usermobileinfo;
@Repository
public class NoticeItemDAO extends BasicDao  {
	private static final Log log = LogFactory.getLog(NoticeItemDAO.class);
	//property constants

    public void save(NoticeItem transientInstance) {
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(NoticeItem persistentInstance) {
        log.debug("deleting NoticeItem instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public NoticeItem findById( java.lang.Integer id) {
        log.debug("getting NoticeItem instance with id: " + id);
        try {
        	NoticeItem instance = (NoticeItem) getSession().get(NoticeItem.class, id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(NoticeItem instance) {
        log.debug("finding NoticeItem instance by example");
        try {
            List results = getSession()
                    .createCriteria("NoticeItem")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
	public List findAll() {
		log.debug("finding all NoticeItem instances");
		try {
			String queryString = "from NoticeItem";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public NoticeItem merge(NoticeItem detachedInstance) {
        log.debug("merging NoticeItem instance");
        try {
        	NoticeItem result = (NoticeItem) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(NoticeItem instance) {
        log.debug("attaching dirty NoticeItem instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(NoticeItem instance) {
        log.debug("attaching clean NoticeItem instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    public List findByQuery(String query) {
		return getSession().createQuery(query).list();
	}
}
